#!/usr/bin/env Rscript
cmd_args = commandArgs(TRUE)

options(stringsAsFactors=FALSE)
library(multicore)
library(xlsx)

gl = read.xlsx("gene_list_final.xlsx", sheetIndex=1)
final_list = subset(gl, !is.na(GeneName), select = c("GeneName", "Source"))
final_list = data.frame(final_list, Priority = 1)

eric = gl$GeneName_new
eric = eric[!is.na(eric)]
pri2 = data.frame( GeneName = setdiff(eric, final_list$GeneName), Source = "In-house", Priority = 2)

final_list = rbind(final_list, pri2)

pancan = gl$PanCan
pancan = pancan[!is.na(pancan)]
pri3 = data.frame( GeneName = setdiff(pancan, final_list$GeneName), Source = "TCGA Pan-Cancer", Priority = 3)

final_list = rbind(final_list, pri3)
final_list = subset(final_list, select = c("GeneName", "Priority", "Source"))
write.xlsx(x = final_list, append = TRUE, file = "gene_list_final.xlsx", sheetName = "Final", row.names = FALSE)

